import re


class InfoCollector:
    def __init__(self, td_item, response):
        self.__td_item = td_item
        self.__response = response

    @property
    def td_item(self):
        return self.__td_item

    @td_item.setter
    def td_item(self, value):
            self.__td_item = value

    @property
    def response(self):
        return self.__response

    @response.setter
    def response(self, value):
            self.__response = value

    @property
    def datecollector(self):
        d_value = self.td_item.extract()
        date = re.search(r'\d{4}-\d{2}-\d{2}', d_value)
        if date:
            return date.group(0)

    @property
    def termcollector(self):
        t_value = self.td_item.extract()
        term = re.search(r'\d{7}', t_value)
        if term:
            return term.group(0)

    @property
    def numbercollector(self):
        nums = ''
        for index, num in enumerate(self.td_item.xpath('.//em')):
            ball = num.xpath('.//text()').extract()[0]
            nums = nums + ball + ','

        return nums[0:len(nums) - 1]

    @property
    def get_pagecount(self):
        rescontent = self.response.xpath("//p[@class='pg']/strong[1]/text()")[0]
        return rescontent.extract()

    @property
    def get_currentpage(self):
        currpage = self.response.xpath("//p/strong[last()]/text()")[0]
        return currpage.extract()

    @property
    def get_totalcout(self):
        totalCount = self.response.xpath('//p[@class="pg"]/strong[2]/text()')[0]
        return totalCount
